<template>
  <div>
    <nav-header></nav-header>
    <nav-bread><span>Goods</span></nav-bread>
    <div class="accessory-result-page accessory-page">
      <div class="container">
        <div class="filter-nav">
          <span class="sortby">Sort by:</span>
          <a href="javascript:void(0)" class="default cur">Default</a>
          <a href="javascript:void(0)" class="price">Price
            <svg class="icon icon-arrow-short">
              <use xlink:href="#icon-arrow-short"></use>
            </svg>
          </a>
          <a href="javascript:void(0)" class="filterby stopPop" v-on:click="showFilterPop">Filter by</a>
        </div>
        <div class="accessory-result">
          <!-- filter -->
          <div class="filter stopPop" id="filter" v-bind:class="{'filterby-show':filterBy}">
            <dl class="filter-price">
              <dt>Price:</dt>
              <dd><a href="javascript:void(0)" v-bind:class="{'cur':priceChecked==='all'}"
                     v-on:click="setPriceFilter('all')">All</a></dd>
              <dd v-for="(price,index) in priceFilter" v-on:click="setPriceFilter(index)">
                <a href="javascript:void(0)" v-bind:class="{'cur':priceChecked===index}">
                  {{price.startPrice}} - {{price.endPrice}}
                </a>
              </dd>
            </dl>
          </div>

          <!-- search result accessories list -->
          <div class="accessory-list-wrap">
            <div class="accessory-list col-4">
              <ul>
                <li v-for="item in goodsList">
                  <div class="pic">
                    <a href="#"><img v-lazy="'/static/'+item.productImg" alt=""></a>
                  </div>
                  <div class="main">
                    <div class="name">{{item.productName}}</div>
                    <div class="price">{{item.productPrice}}</div>
                    <div class="btn-area">
                      <a href="javascript:;" class="btn btn--m">加入购物车</a>
                    </div>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="md-overlay" v-show="overLayFlag" v-on:click="showFilterClose"></div>
    <NavFooter></NavFooter>
  </div>
</template>
<script>
  import './../assets/css/base.css'
  import './../assets/css/product.css'
  import NavHeader from './NavHeader'
  import NavFooter from './NavFooter'
  import NavBread from './NavBread'
  import goodsList from './goods.js'
  import axios from 'axios'

  export default {
    data() {
      return {
        goodsList: [],
        priceFilter: [
          {
            startPrice: 0,
            endPrice: 500.00
          },
          {
            startPrice: 501.00,
            endPrice: 1000.00
          },
          {
            startPrice: 1001.00,
            endPrice: 1500.00
          }
        ],
        priceChecked: 'all',
        filterBy: false,
        overLayFlag: false

      }
    },
    components: {
      NavHeader, NavFooter, NavBread
    },
    mounted() {
      this.getGoodsList();
    },
    methods: {
      getGoodsList() {
        this.goodsList = goodsList.result;
      },
      setPriceFilter(index) {
        this.priceChecked = index;
        this.showFilterClose();
      },
      showFilterPop() {
        this.filterBy = true;
        this.overLayFlag = true;
      },
      showFilterClose() {
        this.filterBy = false;
        this.overLayFlag = false;
      }
    }

  }
</script>
